/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Preferences;

import Current.Account;

import java.io.*;

/**
 * @author Fork
 */
public abstract class AccountInUse {

    private static Account accountInUse;
    public static File profile = new File("profile.dtc");

    public static Account getAccountInUse() {
        return accountInUse;
    }

    public static void setAccountInUse(Account accountInUse) {
        AccountInUse.accountInUse = accountInUse;
    }

    public static String toWelcomeLine() {
        StringBuilder st = new StringBuilder();

        st.append(accountInUse.getName());
        st.append(" is a level ");
        st.append(Integer.toString(accountInUse.getLevel()));
        st.append(" ");
        st.append(accountInUse.getRace());
        st.append(" ");
        st.append(accountInUse.getClassDT());

        return st.toString();
    }

    public static String toSavedFile() {
        StringBuilder st = new StringBuilder();

        st.append(accountInUse.getName());
        st.append("_is_a_level_");
        st.append(Integer.toString(accountInUse.getLevel()));
        st.append("_");
        st.append(accountInUse.getRace());
        st.append("_");
        st.append(accountInUse.getClassDT());
        st.append(".dtc");

        return st.toString();
    }

    public static void Save() {
        try {
            FileOutputStream fileOut = new FileOutputStream(profile);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(accountInUse);
            out.close();
            fileOut.close();

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    public static void Load() {
        try {
            FileInputStream fileIn = new FileInputStream(profile);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            accountInUse = (Account) in.readObject();
            in.close();
            fileIn.close();

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}
